package com.yhs.YShop.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yhs.YShop.model.Manage;
import com.yhs.YShop.mongoRepository.ManageMongoRepository;
import com.yhs.YShop.redisUtil.RedisUtils;
import com.yhs.YShop.service.ManageService;


@RequestMapping("manage")
@RestController
public class ManageController {

	@Autowired
	private ManageService manageService;
	@Autowired
//	private ManageMongoRepository manageMongoRepository;
//	@Autowired
//	private ManageElaService manageElaService;
//	@Autowired
//	private ManageElaRepository manageElaRepository;

	@RequestMapping("selectManageSingel")
	public Map<String, Object> selectManageSingel() {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("resultMap", manageService.selectAll());
		return resultMap;
	}

	@RequestMapping("selectManageList")
	public Map<String, Object> selectManageList() {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<Manage> list = manageService.getAll();
		resultMap.put("manageInfo", list);
//		List<Manage> monList = manageMongoRepository.findAll();
//		resultMap.put("mongoList", monList);
		// 获取Redis
		RedisUtils.set("redisInfo", "cddd");
		resultMap.put("redisList", RedisUtils.get("redisInfo"));
		return resultMap;
	}

//	@RequestMapping("selectManageElasticeList")
//	public Map<String, Object> selectManageElasticeList() {
//		Map<String, Object> resultMap = new HashMap<String, Object>();
//		List<Manage> monList = manageMongoRepository.findAll();
//		// 先查询elastic
//		List<Manage> elManages = (List<Manage>) manageElaRepository.findAll();
//		if (elManages == null || elManages.size() < 0) {
//			manageElaRepository.saveAll((Iterable<Manage>) monList);
//		}
//		elManages = (List<Manage>) manageElaRepository.findAll();
//		resultMap.put("elastic", elManages);
//		return resultMap;
//	}
}
